package tw.edu.tku.im.maze;
import org.json.JSONException;
import org.json.JSONObject;


public class EnterRoomReqParser extends PacketParser {
   public static EnterRoomReqParser INSTANCE = new EnterRoomReqParser();
   
   private EnterRoomReqParser() { }
   
   @Override
   public EnterRoomReq parse(JSONObject jsonObj) throws JSONException {
      JSONObject parameter = jsonObj.getJSONObject("parameter");
      int roomID = (Integer)parameter.get("roomID");
      String userID = (String)parameter.get("userID");
      int ticket = (Integer)parameter.get("ticket");
      if(parameter.isNull("roomPassword")) {
         return new EnterRoomReq(roomID, userID, ticket);
      }
      else {
         String roomPassword = (String)parameter.get("roomPassword");
         return new EnterRoomReq(roomID, userID, ticket, roomPassword);
      }
   }

   @Override
   public String acceptName() {
      return "enterRoom";
   }

}
